package com.ruoyi.reservationserver.controller;

import com.ruoyi.reservationserver.entity.Membershiplevels;
import com.ruoyi.reservationserver.service.MembershiplevelsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * &会员级别制度
0-普通用户 无需买卡， 打球一次15元
1-月卡用户  买卡20元，打球一次12元
2-季卡用户 买卡50元，打球一次10元
3-年卡用户 买卡 160元，打球一次8元
(Membershiplevels)表控制层
 *
 * @author makejava
 * @since 2023-07-04 16:21:49
 */
@RestController
@RequestMapping("membershiplevels")
public class MembershiplevelsController {
    /**
     * 服务对象
     */
    @Resource
    private MembershiplevelsService membershiplevelsService;

    /**
     * 分页查询
     *
     * @param membershiplevels 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Membershiplevels>> queryByPage(Membershiplevels membershiplevels, PageRequest pageRequest) {
        return ResponseEntity.ok(this.membershiplevelsService.queryByPage(membershiplevels, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Membershiplevels> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.membershiplevelsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param membershiplevels 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Membershiplevels> add(Membershiplevels membershiplevels) {
        return ResponseEntity.ok(this.membershiplevelsService.insert(membershiplevels));
    }

    /**
     * 编辑数据
     *
     * @param membershiplevels 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Membershiplevels> edit(Membershiplevels membershiplevels) {
        return ResponseEntity.ok(this.membershiplevelsService.update(membershiplevels));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.membershiplevelsService.deleteById(id));
    }

}

